package com.leyou.gateway.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.security.PublicKey;

/**
 * @Auther: xiang
 * @Date: 2019/8/31 15:06
 * @Description:
 */
@Data
@Slf4j
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties implements InitializingBean {
    /**
     * 公钥路径
     */
    private String pubKeyPath;
    /**
     * 公钥
     */
    private PublicKey publicKey;

   private UserTokenPreperties user= new UserTokenPreperties();

   @Data
   public class UserTokenPreperties{
        private String cookieName;
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        try {
            /**
             * 初始化bean之后加载bean
             */
            this.publicKey= RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            log.error("初始化公钥失败!",e );
            throw new RuntimeException(e);
        }
    }
}